package com.lecture.java8.multithreading;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2021/1/14 18:24
 */
public class BankTest {
}

class Bank{
    private Bank(){}


    private static Bank instance = null;

    //静态方法的锁是Bank.class
    public static Bank getInstance() {
        //方式一：效率差
        /*synchronized (Bank.class) {
            if (instance == null) {
                instance = new Bank();
            }
            return instance;
        }*/
        //方式二：效率高
        if (instance == null) {
            synchronized (Bank.class) {
                if (instance == null) {
                    instance = new Bank();
                }
                return instance;
            }
        }
        return instance;
    }
}